package com.jxl.infra.rpc;

import com.jxl.api.UserClientApi;
import com.jxl.dto.AuthUserDto;
import com.jxl.dto.Result;
import com.jxl.infra.entity.UserInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class AuthUserRpc {

    @Resource
    private UserClientApi userClientApi;


    /**
     * 根据用户名查询用户信息
     * @param userName
     * @return
     */
    public UserInfo getUserInfo(String userName){
        AuthUserDto authUserDto = new AuthUserDto();
        authUserDto.setUserName(userName);
        Result<AuthUserDto> userInfo = userClientApi.getUserInfo(authUserDto);
        if (!userInfo.getSuccess()){
            return null;
        }
        AuthUserDto data = userInfo.getData();
        return new UserInfo(data.getUserName(),data.getNickName(),data.getAvatar());
    }
}
